/**
 * 
 */
package me.whily.nutzbook;

import me.whily.nutzbook.bean.User;
import me.whily.nutzbook.service.UserService;

import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.integration.quartz.NutQuartzCronJobFactory;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

/**
 * @author Administrator
 *
 */
public class MainSetup implements Setup {

	public void init(NutConfig nc) {
		Ioc ioc = nc.getIoc();
		Dao dao = ioc.get(Dao.class);
		Daos.createTablesInPackage(dao, "me.whily.nutzbook", false);
		
		// 初始化默认根用户
        if (dao.count(User.class) == 0) {
            UserService us = ioc.get(UserService.class);
            us.add("admin", "123456");
        }
        
        // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
        ioc.get(NutQuartzCronJobFactory.class);
        
        // 测试发送邮件
//        try {
//            HtmlEmail email = ioc.get(HtmlEmail.class);
//            email.setSubject("测试NutzBook");
//            email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
//            email.addTo("txwanghy@163.com");//请务必改成您自己的邮箱啊!!!
//            email.send();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
	}
	
	public void destroy(NutConfig nc) {
		
	}
}
